import cTitle from "components/title";
import { Toast } from "vant";
import yzSubscribe from "components/ui_components/yz_subscribe";
import eplusWithdraw from "../../others/wisdom/components/withdraw.vue";
import { bindDrainageScene } from "../../../fun/modules/drainage_scene";
import jianzhimaoPopup from "../balance/componet/jianzhimaoPopup.vue";
export default {
  data() {
    return {
      Data: [],
      selectBol: true,
      isCheckAll: false,
      checkAll: false,
      checkList: [],
      allCheckList: [],
      unAllCheckList: [],
      datasource: [],

      // 是否提现到微信
      withdrawToWechat: 0,
      // 是否提现到支付宝
      withdrawToAlipay: 0,
      // 提现总金额
      totalwithdrawal: 0.0,
      // 手续费
      poundage: 0.0,
      // 劳务税
      servicetax: 0.0,

      // 是否开启劳务税 手续费 单独费率
      balance_special: false,
      // special_type: "",
      // 单独劳务费
      independent_special: 0.0,
      // 单独手续费
      independent_poundage: 0.0,

      action: "",

      msg: "",

      notice: "",

      popupVisible: false,

      isHx: false,

      converge_pay: {}, // 汇聚

      eup: {},
      show1: false,
      pay_type: "",
      clicktag: 0, // 防止快速点击
      //  汇聚需要的数据
      converge_pay_json: {},
      special_service_tax_text: "", // 自定义劳务税
      service_switch: 0, // 劳务税开关
      show2: false, // 判断
      show3: false, // 银行卡列表
      withList: [], // 银行卡列表
      checkObj: {}, // 选中的银行卡
      poundage_hj: "", // 汇聚提现手续费
      actual_amount: "", // 实际到账金额

      poundage_name: "", //手续费字样
      deduction_love: {}, //爱心值扣除
      TeamDividendModel: false,
      income_name_text: "",
      // 收入提现类型
      income_type: null,
      withType: true,
      withTypeTipsTitle: "",
      withTypeTips: "",
      withTypeTipsIcon: "",
      bankdata: {
        bankname: "",
        Province: "",
        city: "",
        branchName: "",
        card: "",
        name: "",
        idcard: "",
        mobile: ""
      },
      bankInfo: {},
      // ['提现记录','提现规则说明','联系客户']
      toastTxt: [
        {
          name: `${this.fun.initWithdrawal()}记录`,
          url: "presentationRecord"
        },
        {
          name: `${this.fun.initWithdrawal()}规则说明`,
          url: "fa_child"
        },
        {
          name: "联系客服",
          url: "fa_child_two"
        }
      ],
      manualList: [],
      // 填写银行卡信息弹窗
      createCardShow: false,
      // 省市区选择弹窗
      addressShow_p: false,
      district: district, // 地址本地数据
      provinceData: [],
      cityData: [],
      showCityData: [],
      ProvinceId: "",
      addressShow_c: false,
      pay_typeList: [],
      all_withdraw_income: "",
      stickStatus: false,
      // 客服
      customer_service: {},
      // 规则说明
      withdraw_rich_text: {},
      // 客服显示
      customer_show: false,
      // 规则显示
      withdraw_rich_show: false,
      // 独立手续费
      // special_poundage_amount:false
      setWX: false,
      setAlipay: false,
      setinWX: "",
      setinAlipay: "",
      setinAlipayName: "",
      show: false,
      list: [],
      // 兼职猫
      jianzhimao_bank_show: false,
      set_verify: [],
      bank_card_status: false,
      theme_color: "",
      selectWithDrawalTypeInd: ""
    };
  },
  computed: {
    manualCoputed() {
      // console.log(this.pay_typeList, this.selectWithDrawalTypeInd, "selectWithDrawalTypeInd");
      if (this.pay_type == "manual") {
        for (let i = 0; i < this.pay_typeList.button.length; i++) {
          if (this.pay_typeList.button[i].value == "manual") {
            // 手动提现到银行卡 有设置银行卡 卡号和姓名 才显示
            if (this.pay_typeList.button[i].manual_type == 1 && this.pay_typeList.button[i].member_name && this.pay_typeList.button[i].bank_card) {
              return {
                member_name: this.pay_typeList.button[i].member_name,
                bank_card: this.pay_typeList.button[i].bank_card
              };
            }
          }
        }
      }
      return false;
    }
  },
  activated() {
    this.income_type = null;
    this.selectBol = true;
    this.clicktag = 0;
    this.show1 = false;
    this.show = false;
    this.checkAll = false;
    this.checkList = [];
    this.allCheckList = [];
    this.unAllCheckList = [];
    this.datasource = [];
    this.totalwithdrawal = "0.00";
    this.poundage = "0.00";
    this.servicetax = "0.00";
    this.service_switch = 0;

    this.balance_special = false;
    // this.special_type = ""
    this.independent_special = "0.00";
    this.independent_poundage = "0.00";
    this.poundage_hj = "0.00";
    this.actual_amount = "0.00";

    this.getData(); // 初始化数据
    // this.getWithdrawType(); // 获取提现方式

    this.customizeIncome();
    this.dynamicTxt();
    this.theme_color = JSON.parse(localStorage.getItem("yz_basic_info")).theme_color;
  },

  methods: {
    titleTap(e) {
      if (e == "fa_child") {
        this.withdraw_rich_show = true;
      }
      if (e == "fa_child_two") {
        this.customer_show = true;
      }
    },
    onClickLeft() {
      this.withdraw_rich_show = false;
      this.customer_show = false;
    },
    numberToFix(opt) {
      if (opt) {
        const str = opt + ""; //把数字变成string类型
        if (str.indexOf(".") !== -1) {
          //判断是否附带小数
          const intSum = str.substring(0, str.indexOf(".")).replace(/\B(?=(?:\d{3})+$)/g, ","); //取到整数部分
          const dot = str.substring(str.length, str.indexOf(".")); //取到小数部分搜索
          const ret = intSum + dot;
          return ret;
        } else {
          const ret = str.replace(/\B(?=(?:\d{3})+$)/g, ",");
          return ret + ".00";
        }
      } else {
        return "0.00";
      }
    },
    confirmSub(e) {
      this.checkPayWay();
    },
    errorSub(err) {
      console.log(err);
      this.checkPayWay();
    },
    // 单选
    selectBolfun(num) {
      num == 1 ? (this.selectBol = true) : (this.selectBol = false);
    },
    // 单选的时候显示提现金额
    getOnecePrice() {
      let income_type = [];
      this.checkList.forEach(item => {
        income_type.push(item.key_name);
      });
      $http.post("finance.income-withdraw.getMergeServicetax", { income_type }, "loading").then(
        response => {
          if (response.result === 1) {
            this.totalwithdrawal = response.data.sum_amount;
            this.poundage = response.data.poundage_amount;
            this.servicetax = response.data.servicetax_amount;
            this.independent_poundage = response.data.special_poundage_amount;
            this.independent_special = response.data.special_tax_amount;
          } else {
            Toast(response.msg);
          }
        },
        function(response) {
          console.log(response);
        }
      );
    },
    closePopupJZM() {
      this.jianzhimao_bank_show = false;
      this.getWithdrawType(false);
    },
    // 兼职猫 jianzhimao
    getMergeServicetax_jianzhimao() {
      this.set_verify = this.pay_typeList.button[this.selectWithDrawalTypeInd].extra_data?.electronic_sign?.member_set_verify;
      if (!this.pay_typeList.button[this.selectWithDrawalTypeInd].extra_data.bank_card_status) {
        this.bank_card_status = true;
      }
      if (
        this.pay_typeList.button[this.selectWithDrawalTypeInd]?.extra_data?.electronic_mobile_status &&
        !this.pay_typeList.button[this.selectWithDrawalTypeInd].extra_data.electronic_mobile_status.sign
      ) {
        this.$dialog
          .confirm({ title: `请选择签约模式`, confirmButtonText: "代理签约", cancelButtonText: "自行签约" })
          .then(() => {
            // console.log('代理签约,去新页面')
            this.$router.push(this.fun.getUrl("jianzhimaoAgentSign", {}));
          })
          .catch(() => {
            // console.log('自行签约')
            this.jianzhimao_bank_show = true;
          });
        return false;
      }
      return true;
    },
    // 税惠添新 tax_withdraw
    getMergeServicetax_tax() {
      let tax_extra_data = this.pay_typeList.button[this.selectWithDrawalTypeInd].extra_data;
      if (tax_extra_data && tax_extra_data?.electronic_sign) {
        if (tax_extra_data?.electronic_sign?.member_set_verify.length > 0) {
          let set_verify = tax_extra_data?.electronic_sign?.member_set_verify;
          for (let i = 0; i < set_verify.length; i++) {
            if (!set_verify[i].status) {
              this.$dialog.alert({ message: set_verify[i].tips }).then(() => {
                this.$router.push(this.fun.getUrl("tax_withdraw_bank", {}));
              });
              return false;
            }
          }
        }
        return true;
      }
      return true;
    },
    // 云汇算 huiis
    getMergeServicetax_huiis() {
      let huiis_extra_data = this.pay_typeList.button[this.selectWithDrawalTypeInd].extra_data;
      // 银行卡绑定状态
      this.bank_card_status = !huiis_extra_data.bank_card_status;
      if (this.pay_type == "huiis_ali" && !huiis_extra_data.has_alipay) {
        // console.log("选择云汇算支付宝要先验证是否设置支付宝账号")
        this.$dialog
          .confirm({ message: `您未配置支付宝信息，请先修改个人信息中支付宝信息` })
          .then(() => {
            this.$router.push(this.fun.getUrl("info", {}));
          })
          .catch(() => {});
        return false;
      }
      // 用户资料没有完善
      if (!huiis_extra_data.member_info) {
        this.jianzhimao_bank_show = true;
        this.set_verify = huiis_extra_data.member_set_verify;
        return false;
      }
      if (!huiis_extra_data.has_signing) {
        // 没有签约
        this.$router.push(this.fun.getUrl("cloud_pay_money_sign", {}));
        return false;
      }
      return true;
    },
    async getMergeServicetax() {
      if (!this.income_type) {
        Toast(`请先选择${this.fun.initWithdrawal()}类型`);
        return;
      }
      if (!this.pay_type) {
        Toast(`请选择${this.fun.initWithdrawal()}方式`);
        this.getWithdrawType();
        return;
      }
      let income_type = [];
      let check = true;
      this.checkList.forEach(item => {
        income_type.push(item.key_name);
      });
      // console.log(this.pay_type)
      if (this.pay_type == "huiis_ali" || this.pay_type == "huiis_wx" || this.pay_type == "huiis_bank") {
        // 云汇算
        check = this.getMergeServicetax_huiis();
      }
      if (this.pay_type == "tax_withdraw_bank") {
        //税惠添新
        check = this.getMergeServicetax_tax();
      }
      if (this.pay_type == "jianzhimao_bank") {
        // 兼职猫
        check = this.getMergeServicetax_jianzhimao();
      }
      // 汇聚代发薪 插件二开#22063
      if (this.pay_type == "consol_withdraw_wechat" || this.pay_type == "consol_withdraw_alipay" || this.pay_type == "consol_withdraw_bank") {
        check = await this.hJwithdraw_extra();
      }
      // 工猫提现
      if(this.pay_type == 'gong_mall_withdraw_bank' || this.pay_type == 'gong_mall_withdraw_ali'){
        let extra_data = this.pay_typeList.button[this.selectWithDrawalTypeInd].extra_data;
        check = await this.gong_mall_extra(extra_data);
      }
      if(this.pay_type == 'integration_pay_share_huifu_withdraw_bank'){
        let extra_data = this.pay_typeList.button[this.selectWithDrawalTypeInd].extra_data;
        check = await this.huifu_extra(extra_data);
      }
      if (!check) return;
      $http.post("finance.income-withdraw.getMergeServicetax", { income_type }, "loading").then(
        response => {
          if (response.result === 1) {
            console.log(response);
            this.totalwithdrawal = response.data.sum_amount;
            this.poundage = response.data.poundage_amount;
            this.servicetax = response.data.servicetax_amount;
            this.confirmSub();
            // this.getWithdrawType();
          } else {
            Toast(response.msg);
          }
        },
        function(response) {
          console.log(response);
        }
      );

    },
    gong_mall_extra(extra_data){
      if (!extra_data?.has_member_info || ( this.pay_type == 'gong_mall_withdraw_bank' && !extra_data?.has_bank_card ) || (this.pay_type == 'gong_mall_withdraw_ali' && !extra_data?.has_ali_info)) {
        this.$dialog.confirm({ title: `请先完善资料【含姓名，手机号，身份证信息，${this.pay_type == 'gong_mall_withdraw_bank'?'银行卡信息':'支付宝信息】'}?`, confirmButtonText: "确认", cancelButtonText: "取消" }).then(() => {
          this.$router.push(this.fun.getUrl("info", {}));
        });
        return false;
      }
      if (!extra_data?.has_sign) {
        this.$dialog.confirm({ title: `前往签约?`, confirmButtonText: "去签约", cancelButtonText: "取消" }).then(() => {
          window.location.href = extra_data.sign_url;
        });
        return false;
      }
      return true
    },
    huifu_extra(extra_data){
      if (!extra_data?.has_open_account) {
        this.$dialog.confirm({ title: `暂无开户`, confirmButtonText: "去开户", cancelButtonText: "取消" }).then(() => {
          this.$router.push(this.fun.getUrl("userAccount", {}));
        });
        return false;
      }
      if (!extra_data?.has_settle_info) {
        this.$dialog.confirm({ title: `暂无设置银行卡信息`, confirmButtonText: "设置", cancelButtonText: "取消" }).then(() => {
          this.$router.push(this.fun.getUrl("windAccount", {}));
        });
        return false;
      }
      return true;
    },
    hJwithdraw_extra() {
      this.set_verify = this.pay_typeList.button[this.selectWithDrawalTypeInd].extra_data?.electronic_sign?.member_set_verify;
      if (!this.pay_typeList.button[this.selectWithDrawalTypeInd].extra_data.bank_card_status && this.pay_type == "consol_withdraw_bank") {
        this.$dialog.alert({ message: "请填写银行卡信息" }).then(() => {
          this.$router.push(this.fun.getUrl("hJwithdrawType", {}));
        });
        return false;
      }
      if (this.set_verify.length > 0) {
        let set_verify = this.set_verify;
        for (let i = 0; i < set_verify.length; i++) {
          if (!set_verify[i].status) {
            this.$dialog.alert({ message: set_verify[i].tips }).then(() => {
              if (set_verify[i].name != "openid") this.$router.push(this.fun.getUrl("hJwithdrawType", {}));
            });
            return false;
          }
        }
      }
      return true;
    },
    // 获取提现方式
    getWithdrawType(key = true) {
      console.log("--------------------");
      // if(Object.keys(this.pay_typeList).length != 0){
      //   if(key){
      //     this.show1 = true;
      //   }
      //   this.initWithdrawType(response.data);
      //   return
      // }
      $http.get("finance.income-withdraw.get-income-withdraw-mode", { income_type: this.income_type }, "loading").then(
        response => {
          if (response.result === 1) {
            if (key) {
              this.show1 = true;
            }
            console.log(response);
            this.pay_typeList = response.data;
            this.initWithdrawType(response.data);
          } else {
            Toast(response.msg);
          }
        },
        function(response) {
          console.log(response);
        }
      );
    },
    // 获取银行卡列表
    getwithList() {
      $http.get("plugin.converge_pay.frontend.controllers.converge-pay-bank-card.get-bank-card-list").then(res => {
        if (res.result == 1) {
          res.data.map(item => {
            if (res.data.length == 0) {
              this.$dialog.alert({ message: "请先去添加银行卡" });
              setTimeout(() => {
                this.$router.push(this.fun.getUrl("bankCardInformation"));
              }, 2000);
            }
            item.check = false;
            if (item.receiverAccountNoEnc != "" && item.receiverAccountNoEnc != null) {
              item.bankName += "(" + item.receiverAccountNoEnc.substring(item.receiverAccountNoEnc.length - 4) + ")";
            }
          });
          this.withList = res.data;
        } else {
          this.$dialog.alert({ message: res.msg });
        }
      });
    },
    checkOut(item) {
      item.check = !item.check;
      this.withList.map(val => {
        if (val.id == item.id) {
          val.check = !item.check;
        } else {
          val.check = false;
        }
      });
      if (item.check == true) {
        this.show3 = false;
        this.show2 = true;
        this.checkObj = item;
      }
    },
    backTap() {
      this.show2 = false;
      this.show1 = true;
      this.show3 = false;
      this.clicktag = 0;
    },
    gotoList() {
      this.show2 = false;
      this.show1 = false;
      this.show3 = true;
    },
    // 初始化提现方式
    initWithdrawType(data) {
      this.service_switch = data.service_switch;
    },
    // 汇聚提现
    PayWayHj() {
      if (!this.fun.isTextEmpty(this.checkObj.bankName)) {
        this.getTp();
      } else {
        this.$dialog.alert({ message: "请选择银行卡" });
      }
    },
    // 提交银行卡的东西
    getTp() {
      console.log(this.checkObj);
      $http.post("plugin.converge_pay.frontend.controllers.converge-pay-bank-card.set-bank-card", { set: this.checkObj }).then(res => {
        if (res.result == 1) {
          var type = "converge_pay";
          this.withdrawToBalance(type);
        } else {
          this.$dialog.alert({ message: res.msg });
        }
      });
    },
    getGconverge_pay() {
      $http.get("plugin.converge_pay.frontend.controllers.converge-pay-bank-card.get-bank-card").then(res => {
        if (res.result == "1") {
          this.converge_pay_json = res.data;
          this.countTotalPrice();
          this.show2 = true;
          this.show1 = false;
          this.checkObj = res.data;
          this.checkObj.bankName = res.data.bankName + "(" + res.data.receiverAccountNoEnc.substring(res.data.receiverAccountNoEnc.length - 4) + ")";
          this.getwithList(); // 获取银行卡列表
        } else {
          this.$dialog.alert({ message: res.msg });
          setTimeout(() => {
            this.$router.push(this.fun.getUrl("bankCardInformation"));
          }, 2000);
        }
      });
    },
    // 智E+
    eplusClose() {
      this.clicktag = 0;
      this.show = false;
    },
    eplus_withdrawal(val) {
      let extra_data = this.pay_typeList.button[this.selectWithDrawalTypeInd]?.extra_data;
      if (extra_data.is_auth == 0) {
        this.$dialog.alert({ message: "请先完成认证" }).then(() => {
          this.$router.push(this.fun.getUrl("wisdomBindTask", {}));
        });
        return;
      } else {
        //计算总价格
        this.countTotalPrice();
        this.getBankList();
        return;
      }
    },
    onConfirm(e) {
      if (!e.radio) {
        this.$dialog.alert({ message: "请选择银行卡" });
        return;
      }
      this.withdrawToBalance(this.pay_type, e.radio);
    },
    getBankList() {
      $http.get("plugin.eplus-pay.frontend.card.bindCardList", {}, " ").then(res => {
        if (res.result == 1) {
          this.list = res.data;
          this.show = true;
        } else {
          this.$dialog.alert({ message: res.msg });
        }
      });
    },
    // 智E+ end
    stickChange(e) {
      this.stickStatus = e;
    },
    // 初始化数据
    getData() {
      // validate_page 实名认证判断
      $http.get("finance.income-withdraw.get-withdraw", { validate_page: 1 }, "正在获取列表").then(
        response => {
          if (response.result === 1) {
            let isBindDrainageScene = bindDrainageScene({
              scene: 2,
              title: `${this.income_name_text}${this.fun.initWithdrawal()}`
            });
            if (!isBindDrainageScene) return; //爆客码绑定场景

            if (response.data.shop_esign) {
              this.$dialog.alert({ message: "有合同未签署" });
              return this.$router.push(this.fun.getUrl("contractListPlu"));
            }
            if (response.data.need_sign) {
              return this.$dialog
                .alert({
                  title: "提示",
                  message: "请先完成合同签署"
                })
                .then(() => {
                  this.$router.push(this.fun.getUrl("shopSignIndexV2", { scene: 2 }));
                });
            }
            this.all_withdraw_income = response.data.all_withdraw_income ? response.data.all_withdraw_income.toFixed(2) : "";
            this.service_switch = response.data.setting.service_switch;
            this.balance_special = response.data.setting.balance_special;
            this.customer_service = response.data.setting.customer_service || {};
            this.withdraw_rich_text = response.data.setting.withdraw_rich_text || {};
            this.special_type = response.data.special_type;
            this.datasource = response.data.data;
            if (response.data.deduction_love) {
              this.deduction_love = response.data.deduction_love;
            }
            this.Data = response.data.data;
            if (this.Data.length > 0) {
              this.allCheckListInit(response.data.data); // 初始化全选数据
            } else {
              this.$dialog.alert({ message: `暂无可${this.fun.initWithdrawal()}金额` });
            }
          } else {
            Toast(response.msg);
          }
        },
        function(response) {
          Toast(response.msg);
        }
      );
    },

    // 初始化全选数据
    allCheckListInit(data) {
      // this.allCheckList = data
      for (let i = 0; i < data.length; i++) {
        if (!data[i].can) {
          this.unAllCheckList.push(data[i]);
        } else {
          // 全选默认选中default的选项
          if (data[i].income_type === "default") {
            this.allCheckList.push(data[i]);
          }
        }
      }
      // 判断全选状态
      this.isCheckAll = !(this.unAllCheckList.length === this.datasource.length);
    },
    // 银典提现
    withdrawal_silver_point() {
      for (let i = 0; i < this.pay_typeList.button.length; i++) {
        if (this.pay_typeList.button[i].value == "silver_point") {
          if (!this.pay_typeList.button[i].extra_data.bank_card_status) {
            this.$dialog.alert({ message: "该会员未添加默认银行卡" }).then(() => {
              this.$router.push(this.fun.getUrl("memberBank", {}));
            });
            return false;
          }
        }
      }
      return true;
    },
    //判断微信/支付宝/银行卡-好灵工是否注册，未注册则跳转到注册页面
    withdrawal_worker(key) {
      for (let i = 0; i < this.pay_typeList.button.length; i++) {
        if (this.pay_typeList.button[i].value == key) {
          if (this.pay_typeList.button[i].extra_data.is_register == 0) {
            this.$router.push(this.fun.getUrl("WorkerWithdrawType", { path: "withdrawal" }));
            return false;
          }
        }
      }
      return true;
    },
    //提现方式选择监听
    SelectHandle(val) {
      // 在选择方式时候需要监听的两个提现方式 银典和好灵工
      if (this.pay_type == "worker_withdraw_bank" || this.pay_type == "worker_withdraw_wechat" || this.pay_type == "worker_withdraw_alipay") {
        let check = this.withdrawal_worker(this.pay_type);
        if (!check) return;
      }
      if (this.pay_type == "silver_point") {
        let check = this.withdrawal_silver_point(this.pay_type);
        if (!check) return;
      }
      this.dynamicTxt();
      this.show1 = false;
    },
    cardSplice(str) {
      if (!str) return;
      let str_a = str.substr(0, 4);
      let str_b = str.substr(str.length - 4, str.length);
      return `${str_a}****${str_b}`;
    },
    dynamicTxt() {
      let list_button = this.pay_typeList.button;
      if (this.pay_typeList.button && list_button.length > 0) {
        for (let i = 0; i < list_button.length; i++) {
          if (list_button[i].value == this.pay_type) {
            this.withTypeTipsIcon = list_button[i].icon;
            this.withTypeTipsTitle = list_button[i].title;
            this.withTypeTips = list_button[i].tips;
            this.selectWithDrawalTypeInd = i;
            return;
          }
        }
      }
    },
    // 全选监听
    allSelectHandle(value) {
      this.pay_type = "";
      this.withTypeTipsIcon = "";
      if (value.length > 0) {
        this.income_type = value[0].income_type;
      } else {
        this.income_type = null;
      }
      // console.log(this.selectBol,value,'ssss');
      if (value.length == 0) {
        // 提现总金额
        this.totalwithdrawal = 0.0; // 初始化
        // 手续费
        this.poundage = 0.0; // 初始化
        // 劳务费手续费
        this.servicetax = 0.0; // 初始化
        // 单独劳务税
        this.independent_special = 0.0; // 初始化
        // 单独手续费
        this.independent_poundage = 0.0; // 初始化
        this.actual_amount = 0.0; // 初始化
        return;
      }
      this.getOnecePrice();
      if (!this.selectBol) {
        let checkedCount = value.length;
        this.checkAll = checkedCount === this.allCheckList.length;
        // 计算总价格
        this.countTotalPrice();
      }
    },

    // 全选
    allSelect(event) {
      if (this.selectBol) {
        console.log("全选");
        // 监听全选变化
        if (event) {
          this.checkList = this.allCheckList;
          this.income_type = "default";
        } else {
          this.checkList = [];
          this.income_type = null;
        }
        // 计算总价格
        this.countTotalPrice();
      }
    },

    // 计算总价格
    countTotalPrice() {
      this.TeamDividendModel = false;
      // 提现总金额
      this.totalwithdrawal = 0.0; // 初始化
      // 手续费
      this.poundage = 0.0; // 初始化
      // 劳务费手续费
      this.servicetax = 0.0; // 初始化
      // 单独劳务税
      this.independent_special = 0.0; // 初始化
      // 单独手续费
      this.independent_poundage = 0.0; // 初始化
      this.actual_amount = 0.0; // 初始化
      for (let i = 0; i < this.checkList.length; i++) {
        // this.totalwithdrawal += (this.checkList[i].income)
        // this.poundage += (this.checkList[i].goods.poundage)
        this.totalwithdrawal = this.floatAdd(this.totalwithdrawal, this.checkList[i].income);
        this.poundage = this.floatAdd(this.poundage, this.checkList[i].poundage);
        this.poundage_hj = this.poundage;
        this.actual_amount = this.floatAdd(this.actual_amount, this.checkList[i].actual_amount);
        this.servicetax = this.floatAdd(this.servicetax, this.checkList[i].servicetax);
        if (this.checkList[i].type.indexOf("\\TeamDividendModel") >= 0) {
          this.TeamDividendModel = true;
        }
        // 是否有单独余额劳务费
        if (this.balance_special) {
          if (this.special_type == "1") {
            // 最新
            this.independent_special = this.floatAdd(this.independent_special, this.checkList[i].special_service_tax);
            this.independent_poundage = this.floatAdd(this.independent_poundage, this.checkList[i].special_poundage_rate);
          } else {
            this.independent_special = this.floatAdd(this.independent_special, this.checkList[i].special_service_tax);
            this.independent_poundage = this.floatAdd(this.independent_poundage, this.checkList[i].special_poundage);
          }
        }
      }
      this.totalwithdrawal = Number(this.totalwithdrawal.toString()).toFixed(2);
      this.poundage = Number(this.poundage.toString()).toFixed(2);
      this.servicetax = Number(this.servicetax.toString()).toFixed(2);
      // 是否有单独余额劳务费
      if (this.balance_special) {
        // 最新
        if (this.special_type == "1") {
          this.independent_special = Number(this.independent_special.toString().match(/^\d+(?:\.\d{0,2})?/));
          this.independent_poundage = Number(this.independent_poundage.toString().match(/^\d+(?:\.\d{0,2})?/));
        } else {
          this.independent_special = Number(this.independent_special.toString().match(/^\d+(?:\.\d{0,2})?/));
          this.independent_poundage = Number(this.independent_poundage.toString().match(/^\d+(?:\.\d{0,2})?/));
        }
      }
    },

    // 浮点数加法运算
    floatAdd(arg1, arg2) {
      var r1, r2, m;
      try {
        r1 = arg1.split(".")[1].length;
      } catch (e) {
        r1 = 0;
      }
      try {
        r2 = arg2.split(".")[1].length;
      } catch (e) {
        r2 = 0;
      }
      m = Math.pow(10, Math.max(r1, r2));
      return (arg1 * m + arg2 * m) / m;
    },

    // 浮点数减法运算
    floatSub(arg1, arg2) {
      var r1, r2, m, n;
      try {
        r1 = arg1.split(".")[1].length;
      } catch (e) {
        r1 = 0;
      }
      try {
        r2 = arg2.split(".")[1].length;
      } catch (e) {
        r2 = 0;
      }
      m = Math.pow(10, Math.max(r1, r2));
      // 动态控制精度长度
      n = r1 == r2 ? r1 : r2;
      return ((arg1 * m - arg2 * m) / m).toFixed(n);
    },

    // 验证手动打款的 设置 微信 支付 银行卡 是否完善
    checkManual(type) {
      // 验证是否选择提现数据
      if (!this.checkWithdrawToBalance()) {
        return;
      }
      var that = this;
      $http.post("finance.manual-type.is-can-submit", {}, "").then(
        function(response) {
          that.clicktag = 0;
          if (response.result === 1) {
            if (response.data.status) {
              that.withdrawToBalance(type); // 提现
            } else {
              that.setManualInfo(type, response.data.manual_type);
            }
          } else {
            that.$dialog.alert({ message: response.msg });
          }
        },
        function(response) {
          that.clicktag = 0;
          that.$dialog.alert({ message: response.msg });
        }
      );
    },
    // 验证易宝是否注册
    checkyop_pay(type) {
      // 验证是否选择提现数据
      if (!this.checkWithdrawToBalance()) {
        return;
      }
      var that = this;
      $http.get("plugin.yop-pay.api.yop-verification", {}, "").then(
        function(response) {
          that.clicktag = 0;
          if (response.result === 1) {
            that.withdrawToBalance(type); // 提现
          } else {
            that.$dialog.alert({ message: response.msg });

            that.$router.push(that.fun.getUrl("info", {}));
          }
        },
        function(response) {
          that.clicktag = 0;
          that.$dialog.alert({ message: response.msg });
        }
      );
    },

    setManualInfo(type, manual_type) {
      let msg = "";
      let routerPath = "";

      switch (manual_type) {
        case "bank":
          msg = "请先填写银行卡信息";
          routerPath = "memberBank";
          break;
        case "wechat":
          msg = "请先填写微信信息";
          routerPath = "wx";
          break;
        case "alipay":
          msg = "请先填写支付宝信息";
          routerPath = "Alipay";
          break;
        default:
          break;
      }

      // let that = this
      this.$dialog
        .alert({ message: msg })
        .then(() => {
          if (routerPath == "memberBank") {
            this.getBankCard();
          } else if (routerPath == "wx") {
            this.setWX = true;
          } else if (routerPath == "Alipay") {
            this.setAlipay = true;
            // this.$router.push(this.fun.getUrl(routerPath));
          }
        })
        .catch(() => {});
    },
    addressShowProvince() {
      if (this.provinceData.length > 0) {
        this.createCardShow = false;
        this.addressShow_p = true;
      } else {
        $http.post("member.member-address.address", "").then(
          response => {
            if (response.result == 1) {
              this.provinceData = response.data.province;
              this.cityData = response.data.city;
              this.createCardShow = false;
              this.addressShow_p = true;
            }
          },
          response => {
            that.$dialog.alert({ message: response.msg });
          }
        );
      }
    },
    editUser() {
      this.getBankCard();
    },
    addressShowCity() {
      if (!this.ProvinceId) {
        Toast("请先选择省");
        return;
      }
      this.createCardShow = false;
      this.addressShow_c = true;
      for (let i = 0; i < this.cityData.length; i++) {
        if (this.cityData[i].parentid == this.ProvinceId) {
          this.showCityData = this.showCityData.concat(this.cityData[i]);
        }
      }
    },
    addressCallback(e) {
      this.bankdata.Province = e.areaname;
      this.ProvinceId = e.id;
      this.showCityData = [];
      this.bankdata.city = "";
      this.createCardShow = true;
      this.addressShow_p = false;
    },
    addressCallback_c(e) {
      this.bankdata.city = e.areaname;
      this.createCardShow = true;
      this.addressShow_p = false;
      this.addressShow_c = false;
    },
    onCancel(e) {
      this.createCardShow = true;
      this.addressShow_p = false;
      this.addressShow_c = false;
    },
    // 获取银行卡信息
    getBankCard() {
      let json = {};
      let that = this;
      $http.post("member.bank-card.show", json, "").then(
        response => {
          if (response.result == 1) {
            this.bankdata.bankname = response.data.bank_name;
            this.bankdata.card = response.data.bank_card;
            this.bankdata.name = response.data.member_name;
            this.bankdata.Province = response.data.bank_province;
            this.bankdata.city = response.data.bank_city;
            this.bankdata.branchName = response.data.bank_branch;
            this.bankdata.idcard = response.data.idcard;
            this.bankInfo = response.data;
            console.log(this.bankInfo.hasOwnProperty("mobile"));
            if (this.bankInfo.hasOwnProperty("mobile")) {
              //查询对象有没有这个属性名，后端返回字段就是开关开启，没有返回就是关闭
              this.bankdata.mobile = response.data.mobile;
            }
            if (this.bankInfo.hasOwnProperty("idcard")) {
              this.bankdata.idcard = response.data.idcard;
            }
            this.createCardShow = true;
          } else {
            that.$dialog.alert({ message: response.msg });
          }
        },
        response => {
          that.$dialog.alert({ message: response.msg });
        }
      );
    },
    // 微信号设置
    bindSet(key) {
      let json = {};
      if (key == "wx") {
        if (this.fun.isTextEmpty(this.setinWX)) {
          Toast("请输入微信号");
          return;
        }
        json.wx = this.setinWX;
      } else {
        if (this.fun.isTextEmpty(this.setinAlipay)) {
          Toast("请输入支付宝账号");
          return;
        }
        if (this.fun.isTextEmpty(this.setinAlipayName)) {
          Toast("请输入支付宝账号姓名");
          return;
        }
        json.alipay = this.setinAlipay;
        json.alipay_name = this.setinAlipayName;
      }
      $http.post("member.member.updateWxOrAli", json, "绑定中...").then(
        response => {
          if (response.result == 1) {
            Toast(response.msg);
            this.setWX = false;
            this.setAlipay = false;
          } else {
            this.setWX = false;
            this.setAlipay = false;
            Toast(response.msg);
          }
        },
        response => {}
      );
    },
    // 银行卡信息提交
    bindCard() {
      if (this.fun.isTextEmpty(this.bankdata.bankname)) {
        Toast({
          message: "请输入开户行",
          timeout: 1500
        });
        return;
      }

      if (this.fun.isTextEmpty(this.bankdata.Province)) {
        Toast({
          message: "请输入开户行省份",
          timeout: 1500
        });
        return;
      }

      if (this.fun.isTextEmpty(this.bankdata.city)) {
        Toast({
          message: "请输入开户行城市",
          timeout: 1500
        });
        return;
      }

      if (this.fun.isTextEmpty(this.bankdata.branchName)) {
        Toast({
          message: "请输入开户行支行",
          timeout: 1500
        });
        return;
      }

      if (this.fun.isTextEmpty(this.bankdata.card)) {
        Toast({
          message: "请输入账号",
          timeout: 1500
        });
        return;
      }

      if (this.fun.isTextEmpty(this.bankdata.name)) {
        Toast({
          message: "请输入姓名",
          timeout: 1500
        });
        return;
      }
      if (this.fun.isTextEmpty(this.bankdata.idcard) && this.bankInfo.hasOwnProperty("idcard")) {
        Toast({
          message: "请输入身份证",
          timeout: 1500
        });
        return;
      }
      if (this.fun.isTextEmpty(this.bankdata.mobile) && this.bankInfo.hasOwnProperty("mobile")) {
        Toast({
          message: "请输入银行卡预留手机号",
          timeout: 1500
        });
        return;
      }

      let json = {
        bank_card: this.bankdata.card,
        member_name: this.bankdata.name,
        bank_name: this.bankdata.bankname,
        bank_province: this.bankdata.Province,
        bank_city: this.bankdata.city,
        bank_branch: this.bankdata.branchName
      };
      if (this.bankInfo.hasOwnProperty("idcard")) {
        json.idcard = this.bankdata.idcard;
      }
      if (this.bankInfo.hasOwnProperty("mobile")) {
        json.mobile = this.bankdata.mobile;
      }
      $http.post("member.bank-card.edit", json, "绑定中...").then(
        response => {
          if (response.result == 1) {
            Toast(response.msg);
            this.createCardShow = false;
            this.getWithdrawType(false);
          } else {
            Toast(response.msg);
          }
        },
        response => {}
      );
    },

    // 验证是否选择提现数据
    checkWithdrawToBalance() {
      if (parseFloat(this.totalwithdrawal) <= 0 || this.totalwithdrawal == null) {
        this.clicktag = 0;
        this.$dialog.alert({ message: `${this.fun.initWithdrawal()}金额不能等于0` });

        return false;
      } else {
        return true;
      }
    },

    // 提现网络操作
    withdrawToBalance(type, bank_card_no = "") {
      // 验证是否选择提现数据
      if (!this.checkWithdrawToBalance()) {
        return;
      }

      if (this.checkList.length > 0) {
        var data = {
          total: {
            amounts: this.totalwithdrawal,
            poundage: this.poundage,
            pay_way: type
          },
          withdrawal: this.checkList
        };
        if (type == "eplus_withdraw_bank") {
          data.bank_card_no = bank_card_no;
        }
        // finance.Income-withdraw.save-withdraw
        $http.post("withdraw.apply.index", { data: data }, "正在提交数据").then(response => {
          this.clicktag = 0;
          if (response.result === 1) {
            this.$dialog.alert({ message: response.msg }).then(() => {
              if (type == "eplus_withdraw_bank") {
                this.show = false;
              }
              this.show1 = false;
              this.totalwithdrawal = "0.00";
              this.poundage = "0.00";
              this.checkList = [];
              this.getData();
            });
            this.show2 = false;
          } else {
            this.$dialog
              .confirm({ message: response.msg })
              .then(() => {
                if (response.data.status == 1) {
                  this.$router.push(this.fun.getUrl("info"));
                }
                if (response.data.yee_pay == 1) {
                  this.$router.push(this.fun.getUrl("YeePay"));
                }
                if (response.data.high_light === 1) {
                  this.$router.push(this.fun.getUrl("HighLight", { value: this.pay_type }));
                }
                if (response.data.love == 1) {
                  // 任务编号: 46649
                  this.$router.push(this.fun.getUrl("love_index"));
                }
              })
              .catch(() => {});
          }
          setTimeout(() => {
            this.clicktag = 0;
          }, 1000);
        });
      } else {
        this.clicktag = 0;
        this.$dialog.alert({ message: `${this.fun.initWithdrawal()}数据不可为空` });
        this.clicktag = 0;
      }
    },

    checkEup(type) {
      // 验证是否选择提现数据
      if (!this.checkWithdrawToBalance()) {
        return;
      }
      var that = this;
      $http.post("plugin.eup-pay.api.account.pi-account", {}, "").then(
        response => {
          this.clicktag = 0;
          if (response.result == 1) {
            if (response.data.bool == 1) {
              that.withdrawToBalance(type); // 提现
            }
          } else if (response.result == 0) {
            if (response.data.bool == 0) {
              this.$dialog
                .alert({ message: response.msg })
                .then(() => {
                  this.$router.push(this.fun.getUrl("info"));
                })
                .catch(() => {});
            }
          }
        },
        function(response) {
          this.clicktag = 0;
          this.$dialog.alert({ message: response.msg });
        }
      );
    },

    checkPayWay() {
      if (!this.pay_type) {
        Toast(`请选择${this.fun.initWithdrawal()}方式`);
        this.getWithdrawType();
        return;
      }
      if (this.pay_type == "converge_pay" && this.clicktag == 1) {
        // 再次调用汇聚提现
        this.getGconverge_pay();
      }
      console.log(this.clicktag,'clicktag')
      if (this.clicktag === 0) {
        this.clicktag = 1;
        switch (this.pay_type) {
          case "manual":
            this.checkManual(this.pay_type);
            break;
          case "eup":
            this.checkEup(this.pay_type);
            break;
          case "yop_pay":
            this.checkyop_pay(this.pay_type);
            break;
          case "converge_pay":
            this.getGconverge_pay();
            break;
          case "eplus_withdraw_bank":
            this.eplus_withdrawal(this.pay_type);
            break;
          default:
            this.withdrawToBalance(this.pay_type);
            break;
        }
      }
    },
    // 自定义提现收入语言
    customizeIncome() {
      let mailLanguage = this.fun.initMailLanguage();
      //自定义劳务税字段
      this.special_service_tax_text = mailLanguage.income.special_service_tax;
      //自定义收入字段
      this.income_name_text = mailLanguage.income.income_name;
      console.log(this.income_name_text);
      //自定义手续费字段
      this.poundage_name = this.fun.initMailLanguage().income.poundage_name;
      this.fun.setWXTitle(`${this.income_name_text}${this.fun.initWithdrawal()}`);
    }
  },

  components: { cTitle, yzSubscribe, eplusWithdraw, jianzhimaoPopup }
};
